package com.systemsjr.jrenterprise.appointment;

import javax.swing.JTable;
import javax.swing.table.TableColumnModel;

import com.systemsjr.jrenterprise.appointment.vo.AppointmentVO;
import com.systemsjr.jrenterprise.utils.ServiceUtils;
import com.systemsjr.jrlib.richclient.BaseItemTable;

public class AppointmentTable extends BaseItemTable<AppointmentVO> {

	public AppointmentTable(AppointmentVO[] data, String modelId,
			String[] columnPropertyNames) {
		super(data, modelId, columnPropertyNames);
	}
	
	public AppointmentTable(){
		this(new AppointmentVO[]{}, "appointments", new String[]{
				"customer.phoneNumber",
				"customer.name",
				"startTime"
		});
	}

	@Override
	protected void configureTable(JTable table) {
		super.configureTable(table);
		TableColumnModel tcm = table.getColumnModel();
		tcm.getColumn(0).setPreferredWidth(10);
		tcm.getColumn(1).setPreferredWidth(50);
		tcm.getColumn(2).setPreferredWidth(10);
	}

	@Override
	public JTable getItemTable(){
		JTable table = getTable();
		if(table != null){
			return table;
		}
		return null;
	}
	
	@Override
	protected Object[] getDefaultInitialData() {
		setInitialData(ServiceUtils.getAppointmentService().loadAll().toArray());
		return getInitialData();
	}
	
	@Override
	protected void setViewId(String id) {
		viewId = id;
	}	
}
